package com.lyy.controller;

import com.lyy.entity.Util.ExcelUtil;
import com.lyy.entity.excel.UserExcel;
import lombok.Data;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author Liangyaoyun
 */
@Data
@RequestMapping("/api/v1/excel")
public class ExcelController {
    @SneakyThrows
    @ResponseBody
    @RequestMapping("/excel")
    public void exe(HttpServletResponse resp) {
        UserExcel zhaosi = new UserExcel();
        zhaosi.setUserId(1);
        zhaosi.setUsername("zhaosi");
        zhaosi.setPassword("zhaosi123");
        zhaosi.setRealName("赵四");
        zhaosi.setCreateTime(new Date());
        zhaosi.setModifyTime(new Date());
        UserExcel liuneng = new UserExcel();
        liuneng.setUserId(2);
        liuneng.setUsername("liuneng");
        liuneng.setPassword("liuneng123");
        liuneng.setRealName("刘能");
        liuneng.setCreateTime(new Date());
        liuneng.setModifyTime(new Date());
        List<UserExcel> userExcels = Arrays.asList(zhaosi, liuneng);
        ExcelUtil.writeExcel(resp, userExcels, "用户统计表.xlsx");
    }
}
